package com.approval.approvalapp.center.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.HyListBean;
import com.approval.approvalapp.center.acitivty.HyspXqActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by louyulin on 2019/5/11.
 */

public class HysplistDbAdapter extends RecyclerView.Adapter<
        HysplistDbAdapter.Holder> {

    Context context;
    List<HyListBean> rvList;

    public void setRvList(List<HyListBean> rvList) {
        this.rvList = rvList;
        notifyDataSetChanged();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context)
                .inflate(R.layout.item_hyspdb, parent, false);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(Holder holder, final int position) {
        holder.tv1.setText(rvList.get(position).getXNAME() + "的会议申请-"+rvList.get(position).getImPlaceN());
        holder.tv2.setVisibility(View.GONE);
        holder.tv3.setText("会议主题: " + rvList.get(position).getImTitle());
        holder.tv4.setText("开始时间: " + rvList.get(position).getImStartTime());
        holder.tv5.setText("结束时间: " + rvList.get(position).getImEndTime());


        holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, HyspXqActivity.class);
                intent.putExtra("name" , rvList.get(position).getXNAME());
                intent.putExtra("id" , rvList.get(position).getID());
                intent.putExtra("ImTitle" , rvList.get(position).getImTitle());
                intent.putExtra("ImStartTime" , rvList.get(position).getImStartTime());
                intent.putExtra("ImEndTime" , rvList.get(position).getImEndTime());
                intent.putExtra("ImStart" , rvList.get(position).getImStart());
                intent.putExtra("ImUserNo" , rvList.get(position).getImUserNo());
                intent.putExtra("tel" , rvList.get(position).getTEL());
                intent.putExtra("place" , rvList.get(position).getImPlaceN());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        if (rvList == null) {
            return 0;
        } else {
            return rvList.size();
        }
    }

    class Holder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv1)
        TextView tv1;
        @Bind(R.id.tv2)
        TextView tv2;
        @Bind(R.id.tv3)
        TextView tv3;
        @Bind(R.id.tv4)
        TextView tv4;
        @Bind(R.id.tv5)
        TextView tv5;
        @Bind(R.id.root)
        LinearLayout root;
        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
